package lec03.pm.ex;


public class Stack implements List{
	private static  int CAPACITY = 5;

	Stack()
	{
		data=new int[CAPACITY];
		size=0;
	}
	
	
	int[] data;
	int size;
	
	@Override
	public int pop() {
		
		return data[--size];
	}

	@Override
	public void push(int x) {
		if(size==CAPACITY)
		{
			int copy[]=new int[CAPACITY*2];
			System.arraycopy(data, 0, copy, 0, size);
			data=copy;
			CAPACITY*=2;
		}
		data[size++]=x;	
		
	}

	@Override
	public void disp() {
		for(int i=0;i<size;i++)
			System.out.print(data[i]+" ");
		System.out.println();
		
	}
	
	public static void main(String[] args) {
		Stack s=new Stack();
		for(int i=0;i<2000;i++)
		{
			s.push(i);
			s.disp();
		}
	}

}
